home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MACD 5
/
MACD 5.bin
/
internet
/
yam_i_dodatki
/
yamnet
/
src
/
crc32.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-11-02
|
1KB
|
55 lines
/*
** $VER: CRC32.c (16.4.94) by Flavio Stanchina
** Adapted from comp.compression FAQ
**
** Changed to do one-byte-at-a-time CRC
** Don't complement CRC for simplicity
*/
#include <exec/types.h>
#include "CRC32.h"
ULONG crc32_table[256];
/*
** Build auxiliary table for parallel byte-at-a-time CRC-32.
*/
VOID CRC32_init(VOID)
{
ULONG c, i, j;
for(i = 0; i < 256; ++i)
{
for(c = i << 24, j = 8; j > 0; --j)
c = c & 0x80000000 ? (c << 1) ^ CRC32_POLY : (c << 1);
crc32_table[i] = c;
}
}
ULONG CRC32_stream(UBYTE c, ULONG crc)
{
return (crc << 8) ^ crc32_table[(crc >> 24) ^ c];
}
ULONG CRC32_block(UBYTE *buf, ULONG len)
{
ULONG crc = CRC32_INITIAL;
UBYTE *p;
for(p = buf; len > 0; ++p, --len)
crc = (crc << 8) ^ crc32_table[(crc >> 24) ^ *p];
return crc; /* to simplify some things */
}
ULONG CRC32_blocks(UBYTE *buf, ULONG len, ULONG crc)
{
UBYTE *p;
for(p = buf; len > 0; ++p, --len)
crc = (crc << 8) ^ crc32_table[(crc >> 24) ^ *p];
return crc; /* to simplify some things */
}